#ifndef OHOS_EGL_RENDER_H_
#define OHOS_EGL_RENDER_H_

#include <EGL/egl.h>
#include <EGL/eglext.h>
#include <GLES3/gl3.h>
#include "common_video/ohos/ohos_gl_drawer.h"
#include "common_video/ohos/ohos_egl_render_context.h"

namespace webrtc {
class EGLRender: public OhosGLDrawer {
 public:
  EGLRender() = default;
  virtual ~EGLRender() = default;
  bool InitContext(void *window, void* share_context, int width, int height);
  void SetBackgroundColor(const GLfloat color[]);
  void ClearColor(const GLfloat color[]);
  void DrawFrame(OhosVideoBuffer::TextureBuffer buffer, float *matrix, int frameWidth, int frameHeight, int viewportX, int viewportY, int viewportWidth, int viewportHeight) override;
  void Release();
  void UpdateSize(int width, int height);
  bool HasSurface();

 private:
  GLboolean PrepareDraw();
  bool FinishDraw();
  static void ClearBufferColor(const GLfloat color[]);

 private:
  std::shared_ptr<OhosGLDrawer> glDrawer_ = nullptr;
  std::shared_ptr<EGLRenderContext> eglRenderContext_ = nullptr;
  EGLSurface eglSurface_ = EGL_NO_SURFACE;
  int width_ = 0;
  int height_ = 0;
  GLfloat background_color_[4] = {0.f, 0.f, 0.f, 0.f};
};
}
#endif
